home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / f_invert.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  2.2 KB  |  110 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <windows.h>
  21. #include <commctrl.h>
  22.  
  23. #include "resource.h"
  24. #include "filter.h"
  25.  
  26. extern HINSTANCE g_hInst;
  27.  
  28. ///////////////////////////////////
  29.  
  30. void __declspec(naked) asm_invert_run(Pixel32 *data, long w, long h, long pitch) {
  31.     __asm {
  32.         push    ebp
  33.         push    edi
  34.         push    esi
  35.         push    ebx
  36.  
  37.         mov        edi,[esp+4+16]
  38.         mov        edx,[esp+8+16]
  39.         mov        ecx,[esp+12+16]
  40.         mov        esi,[esp+16+16]
  41.         mov        eax,edx
  42.         xor        edx,-1
  43.         shl        eax,2
  44.         inc        edx
  45.         add        edi,eax
  46.         test    edx,1
  47.         jz        yloop
  48.         sub        edi,4
  49. yloop:
  50.         mov        ebp,edx
  51.         inc        ebp
  52.         sar        ebp,1
  53.         jz        zero
  54. xloop:
  55.         mov        eax,[edi+ebp*8  ]
  56.         mov        ebx,[edi+ebp*8+4]
  57.         xor        eax,-1
  58.         xor        ebx,-1
  59.         mov        [edi+ebp*8  ],eax
  60.         mov        [edi+ebp*8+4],ebx
  61.         inc        ebp
  62.         jne        xloop
  63. zero:
  64.         test    edx,1
  65.         jz        notodd
  66.         not        dword ptr [edi]
  67. notodd:
  68.         add        edi,esi
  69.         dec        ecx
  70.         jne        yloop
  71.  
  72.         pop        ebx
  73.         pop        esi
  74.         pop        edi
  75.         pop        ebp
  76.         ret
  77.     };
  78. }
  79.  
  80. ///////////////////////////////////
  81.  
  82. int invert_run(const FilterActivation *fa, const FilterFunctions *ff) {    
  83.     asm_invert_run(
  84.             fa->src.data,
  85.             fa->src.w,
  86.             fa->src.h,
  87.             fa->src.pitch
  88.             );
  89.  
  90.     return 0;
  91. }
  92.  
  93. long invert_param(FilterActivation *fa, const FilterFunctions *ff) {
  94.     fa->dst.offset = fa->src.offset;
  95.     return 0;
  96. }
  97.  
  98. FilterDefinition filterDef_invert={
  99.     0,0,NULL,
  100.     "invert",
  101.     "Inverts the colors in the image.\n\n[Assembly optimized]",
  102.     NULL,NULL,
  103.     0,
  104.     NULL,NULL,
  105.     invert_run,
  106.     invert_param,
  107.     NULL,
  108.     NULL,
  109. };
  110.